package com.qianxing.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.qianxing.exceptionhandler.ResponseException;
import com.qianxing.service.TbMsgDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:JasonLong
 * @Date:2023/7/10
 * @Time:9:55
 */
@Api("精彩节庆文章管理")
@RestController
@RequestMapping("/msg")
public class WxMsgDataController {

    @Autowired
    TbMsgDataService msgDataService;

    @ApiOperation("查询所有文章")
    @ApiImplicitParam(name = "获取所有文章数据")
    @GetMapping("/queryAll")
    public ResponseException queryAllData() {
        try {
            return msgDataService.queryAllData();
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 当每个用户进入节庆文章的子页面的时候存储主页点击的对应文章的文章id
     *
     * @param msgId
     * @return
     */
    @ApiOperation("设置文章id唯一键")
    @GetMapping("/setMsgKey")
    public ResponseException setMsgKey(String msgId, String userId) {
        System.err.println("入参:" + msgId + "---" + userId);
        return msgDataService.setCurrentMsgKey(msgId, userId);//返回存储的键
    }

    @ApiOperation("获取文章数据")
    @GetMapping("/getMsgKey")
    public ResponseException getMsgDataByKey(@RequestParam("userId") String userId) {
        return msgDataService.getCurrentMsg(userId);
    }

    @ApiOperation("添加节庆文章")
    @ApiImplicitParam(name = "")
    @PostMapping("/addMsg")
    public ResponseException addMsg() {
        return null;
    }

    @GetMapping("/delMsg")
    public ResponseException delMsg(String msgId) {
        return null;
    }
}
